function domdown(patches, slices, max)

patches = [patches; [slices(1, 1), slices(1, 2), max(1)-slices(1, 1), max(2) - slices(1, 2)]];
newpatches = [];

e = 0.0001;
ez = 0.0001;

for i = 1:size(patches, 1)
  p = patches(i, :);
  s = slices(1, :);

  % Draw patch downto next Z
  %hold on
  %scatter3(s(1), s(2), s(3), 100, 'k', 'filled');
  %hold off

  if size(slices, 1) > 1
    domfront([p(1), p(2), s(3)], [p(3)-e, p(4)-e, slices(2, 3)-s(3)+ez])
  else
    domfront([p(1), p(2), s(3)], [p(3)-e, p(4)-e, max(3)-s(3)+ez])
  end

  if size(slices, 1) > 1
    % Find out overlap with next slice
    ns = slices(2, :);
    np = [];
    if p(1) < ns(1)
      np = [np; [p(1), p(2), min([ns(1)-p(1), p(3)]), p(4)]];
      if p(2) < ns(2)
        np = [np; [p(1), p(2), min([ns(1), p(3)]), min([ns(2)-p(2), p(4)])]];
      end
    else
      if p(2) < ns(2)
        np = [np; [p(1), p(2), p(3), min([ns(2)-p(2), p(4)])]];
      end
    end

    newpatches = [newpatches; np];
  end
end

%input([num2str(size(newpatches, 1)) ' patches']);

if size(slices, 1) > 1
  % Recurse
  domdown(newpatches, slices(2:end, :), max);
end
  